package com.dingreading.cloud.admin.util;

import com.dingreading.cloud.admin.entity.StoreFollow;
import com.dingreading.cloud.admin.entity.StoreFollowType;
import com.dingreading.cloud.admin.service.StoreFollowService;
import com.dingreading.cloud.admin.service.StoreFollowTypeService;
import com.dingreading.cloud.common.util.DateUtil;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 门店跟进记录实体工具
 */
@Component
public class StoreFollowUtil {

    @Resource
    private StoreFollowTypeService followTypeService;
    @Resource
    private StoreFollowService followService;

    public static StoreFollowUtil util;

    @PostConstruct
    public void init() {
        util = this;
    }

    public static void newSystemLog(
            String followTypeUid,String content, String corpUid, String storeUid, String staffUid, String staffName
    ) {
        StoreFollowType followType = util.followTypeService.getByUid(followTypeUid);
        if (followType != null) {
            StoreFollow data = new StoreFollow();
            data.setAddStaffUid(staffUid);
            data.setAddStaffName(staffName);
            data.setLastStaffUid(staffUid);
            data.setLastStaffName(staffName);
            data.setCorpUid(corpUid);
            data.setStoreUid(storeUid);
            data.setContent(content);
            data.setFollowTime(DateUtil.getNowDatetime());
            data.setFollowTypeUid(followTypeUid);
            data.setFollowTypeName(followType.getName());
            data.setSource(followType.getSource());
            data.setOperation(followType.getOperation());
            util.followService.saveOrUpdate(data);
        }
    }

}
